package com.smart.car.member.feign.fallback;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.smart.car.common.res.bean.ResponseResult;
import com.smart.car.common.res.entity.PointsInfo;
import com.smart.car.common.res.exception.BusinessException;
import com.smart.car.member.feign.PointsFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 默认快速失败方案,【类模式】。调用出现异常时候，快速响应，防止服务雪崩。
 * 跟Sentinel的fallback配置效果相同，二选一即可。
 * @author: zoutao
 * @date: 2021-04-25
 */
@Slf4j
@Component
public class PointsServiceFallback implements PointsFeignService {

    /**
     * 出错则调用该方法快速响应
     */
    @Override
    public ResponseResult getUserPoints(String id) {
        ResponseResult result = new ResponseResult();
        result.setMsg("服务不可用，开始熔断，启动降级快速响应!（您操作太频繁了，请稍后再试~）");
        result.setCode(500);
        log.warn(result.toString());
        return result;
    }

    @Override
    public ResponseResult<PointsInfo> getData(String memberId) {
        ResponseResult result = new ResponseResult();
        result.setMsg("服务不可用，开始熔断，启动降级快速响应!（您操作太频繁了，请稍后再试~）");
        result.setCode(500);
        log.warn(result.toString());
        return result;
    }

    @Override
    public ResponseResult<Integer> addPoints(String json) throws BusinessException {
        return null;
    }
    @Override
    public ResponseResult<Integer> updateCard(String json) throws BusinessException {
        return null;
    }

    @Override
    public ResponseResult getPointsById(String pointsId) {
        return null;
    }
    @Override
    public ResponseResult getPointsByPhone(String phone) {
        return null;
    }

}
